<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery.js"></script>
    <script src="./js/layer/layer.js"></script>
</head>

<body>
    <form>
        <p>
            用户名 <input name="name">
        </p>
        <p>
            密码 <input name="pwd">
        </p>
        <p>
            性别 <input name="sex" checked type="radio" value="男">男
             <input name="sex" type="radio" value="女">女
        </p>
        <p>
            手机号 <input name="tel">
        </p>
        <p>
            邮箱 <input name="email">
        </p>
        <p>
            <button>注册</button>
        </p>
    </form>

    <script>
        $(function () {
            $("form").on("submit", function () {

                var data = $("form").serialize();

                $.ajax({
                    url: "/reg",
                    type: "post",
                    data: data
                }).then(function (res) {
                    console.log(res);
                    let { code, msg, data } = res;
                    if (code == 200) {

                        //是否跳转到主页
                        layer.confirm("注册成功!是否立即登录", {
                            btn: ["确定", "取消"]
                        },(index)=>{
                        
                            layer.close(index);
                            location.href="./login.html";
                        },()=>{

                        })


                    } else {
                        layer.msg(msg);
                    }


                })

                return false;
            })
        })

    </script>
</body>

</html>